package edu.ynu.se.xiecheng.achitectureclass.entity;

import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import java.util.List;
import java.util.Set;

@Entity(name="Orders")
@Getter
@Setter
@Where(clause = "is_deleted = 0")
public class Order extends LogicEntity {
    @Column
    private String orderId;
    @Column
    private boolean isPaid;//支付状态
    @Column
    private boolean isCancelled;//取消状态
    @Column
    private boolean isConfirmed;//确认状态
    @Column
    private boolean isRefunded;//退款状态
    @ManyToOne
    private Customer customer;
    @OneToMany(mappedBy = "order")
    private List<LineItem> lineItems;
    @OneToMany(mappedBy = "order")
    private Set<ShopItem> shopItemSet;
    @ManyToOne
    private ShopItem shopItem;
    @ManyToOne
    private Shop shop;
    public void payOrder() {
        this.isPaid = true;//支付订单
    }
    public void cancelOrder() {
        this.isCancelled = true;//取消订单
    }
    public void confirmOrder() {
        this.isConfirmed = true;//确认订单
    }
    public void refundOrder() {
        this.isRefunded = true;//退款
    }
}
